local L = LibStub("AceLocale-3.0"):GetLocale("DoTimer_Options")
local CURRENT_ANCHOR, CURRENT_TIMER = "", "";
local ANCHOR_FRAMES = {};
local PROFILE_FRAMES = {};

local optionsTable = {
    { -- section 1
        { -- column 1
            {
                title = L["Enabled"],
                type = "checkButton",
                tooltipText = L["Enables or disables the addon."],
                setting = "enabled",
                simple = true,
            },
            {
                title = L["Party Buffs"],
                type = "checkButton",
                tooltipText = L["Enables or disables Party Buffs from appearing.  Party Buffs consolidate buffs you cast on the party into a single timer.  The stack number is the number of people it's on, and the time remaining is from the timer that's going to end first.  You can mouse over the timer for info on who you have timers on, and who you don't."],
                setting = "usePartyBuffs",
                simple = true,
            },
            {
                title = L["No Target"],
                type = "checkButton",
                tooltipText = L["Enables or disables No Target from appearing.  No Target consolidates timers that may appear on many mobs at once (like AOE fears) or no one at all (like totems)."],
                setting = "useNoTarget",
                simple = true,
            },
            {
                title = L["Filter Ungrouped"],
                type = "checkButton",
                tooltipText = L["If checked, buffs you cast on people not in your group will be ignored."],
                setting = "filterUngroupedBuffs",
                simple = true,
            },
            {
                title = L["Filter Non-Players"],
                type = "checkButton",
                tooltipText = L["If checked, buffs you cast on things that aren't players will be ignored."],
                setting = "filterNonPlayerBuffs",
                simple = true,
            },
            {
                title = L["Filter Self"],
                type = "checkButton",
                tooltipText = L["If checked, buffs you cast on yourself will be ignored."],
                setting = "filterSelf",
                simple = true,
            },
            {
                title = L["Mouseover Timers"],
                type = "dropDownSelector",
                tooltipText = L["Sets for whom Mouseover Timers will appear.  When you mouse over a unit, either in the world or over a unit frame, you will get a list of any timers on that unit right next to your cursor.  It will only happen if your mouseover target is not your current target."],
                values = {"off", "friends", "enemies", "both"};
                setting = "mouseoverTimers",
                simple = true,
            },
            {
                title = L["Standard Setting"],
                type = "dropDown",
                tooltipText = L["Select the timer setting you want to apply to standard timers on targets."],
                func = function()
                    local setting = "standardSetting";
                    local info;
                    for name, settings in AsheylaLib:Alphabetize(TimerLib:Get("timerSettings")) do
                        info = UIDropDownMenu_CreateInfo();
                        info.text = name;
                        info.checked = name == DoTimer:Get(setting);
                        info.func = function() 
                            DoTimer:Set(setting, name);
                            CloseDropDownMenus(); 
                        end
                        UIDropDownMenu_AddButton(info);
                    end
                    
                    info = UIDropDownMenu_CreateInfo();
                    info.text = L["None"];
                    info.tooltipTitle = L["Description"];
                    info.tooltipText = L["If you select 'None', the default for the anchor will be used instead."];
                    info.checked = DoTimer:Get(setting) == nil;
                    info.func = function() 
                        DoTimer:Set(setting, nil);
                        CloseDropDownMenus(); 
                    end
                    UIDropDownMenu_AddButton(info);
                end,
            },
            {
                title = L["Party Buffs Setting"],
                type = "dropDown",
                tooltipText = L["Select the timer setting you want to apply to Party Buffs timers."],
                func = function()
                    local setting = "pbSetting";
                    local info;
                    for name, settings in AsheylaLib:Alphabetize(TimerLib:Get("timerSettings")) do
                        info = UIDropDownMenu_CreateInfo();
                        info.text = name;
                        info.checked = name == DoTimer:Get(setting);
                        info.func = function() 
                            DoTimer:Set(setting, name);
                            CloseDropDownMenus(); 
                        end
                        UIDropDownMenu_AddButton(info);
                    end
                    
                    info = UIDropDownMenu_CreateInfo();
                    info.text = L["None"];
                    info.tooltipTitle = L["Description"];
                    info.tooltipText = L["If you select 'None', the default for the anchor will be used instead."];
                    info.checked = DoTimer:Get(setting) == nil;
                    info.func = function() 
                        DoTimer:Set(setting, nil);
                        CloseDropDownMenus(); 
                    end
                    UIDropDownMenu_AddButton(info);
                end,
            },
            {
                title = L["No Target Setting"],
                type = "dropDown",
                tooltipText = L["Select the timer setting you want to apply to No Target Timers."],
                func = function()
                    local setting = "ntSetting";
                    local info;
                    for name, settings in AsheylaLib:Alphabetize(TimerLib:Get("timerSettings")) do
                        info = UIDropDownMenu_CreateInfo();
                        info.text = name;
                        info.checked = name == DoTimer:Get(setting);
                        info.func = function() 
                            DoTimer:Set(setting, name);
                            CloseDropDownMenus(); 
                        end
                        UIDropDownMenu_AddButton(info);
                    end
                    
                    info = UIDropDownMenu_CreateInfo();
                    info.text = L["None"];
                    info.tooltipTitle = L["Description"];
                    info.tooltipText = L["If you select 'None', the default for the anchor will be used instead."];
                    info.checked = DoTimer:Get(setting) == nil;
                    info.func = function() 
                        DoTimer:Set(setting, nil);
                        CloseDropDownMenus(); 
                    end
                    UIDropDownMenu_AddButton(info);
                end,
            },
        },
        { -- column 2
            {
                title = L["Show Only Target"],
                type = "checkButton",
                tooltipText = L["If checked, when you have a target DoTimer will only display timers from it.  If 'Show Only Focus' is also checked, both targets will be shown."],
                setting = "showOnlyTarget",
                simple = true,
            },
            {
                title = L["Sort Target"],
                type = "checkButton",
                tooltipText = L["If checked, your current target will be sorted to the first target position."],
                setting = "sortTarget",
                simple = true,
            },
            {
                title = L["Show Only Focus"],
                type = "checkButton",
                tooltipText = L["If checked, when you have a focus DoTimer will only display timers from it.  If 'Show Only Target' is also checked, both targets will be shown."],
                setting = "showOnlyFocus",
                simple = true,
            },
            {
                title = L["Sort Focus"],
                type = "checkButton",
                tooltipText = L["If checked, your current focus will be sorted to the first target position.  If 'Sort Target' is also checked, your focus will be the 2nd position."],
                setting = "sortFocus",
                simple = true,
            },
            {
                title = L["Apply Always"],
                type = "checkButton",
                tooltipText = L["If checked, the above 'Show Only ...' settings will apply always, instead of just when the units exist."],
                setting = "always",
                simple = true,
            },
            {
                title = L["Announce"],
                type = "checkButton",
                tooltipText = L["If unchecked, attempting to announce a timer will result in no action."],
                setting = "isAnnouncing",
                simple = true,
            },
            {
                title = L["Blocked Types"],
                type = "dropDownMultiSelector",
                tooltipText = L["Allows you to disable timers for different types of spells."],
                values = {"Helpful", "Harmful"};
                setting = "blockedTypes",
                simple = true,
            },
            {
                title = L["Key Bindings"],
                type = "dropDown",
                tooltipText = L["Allows you to change the key bindings for various timer-related functions."],
                func = function() DoTimer:KBDropDown() end,
            },
            {
                title = L["Mouseover Setting"],
                type = "dropDown",
                tooltipText = L["Select the timer setting you want to apply to Mouseover Timers."],
                func = function()
                    local setting = "mouseoverSetting";
                    local info;
                    for name, settings in AsheylaLib:Alphabetize(TimerLib:Get("timerSettings")) do
                        info = UIDropDownMenu_CreateInfo();
                        info.text = name;
                        info.checked = name == DoTimer:Get(setting);
                        info.func = function() 
                            DoTimer:Set(setting, name);
                            CloseDropDownMenus(); 
                        end
                        UIDropDownMenu_AddButton(info);
                    end
                    
                    info = UIDropDownMenu_CreateInfo();
                    info.text = L["None"];
                    info.tooltipTitle = L["Description"];
                    info.tooltipText = L["If you select 'None', the default for the anchor will be used instead."];
                    info.checked = DoTimer:Get(setting) == nil;
                    info.func = function() 
                        DoTimer:Set(setting, nil);
                        CloseDropDownMenus(); 
                    end
                    UIDropDownMenu_AddButton(info);
                end,
            },
            {
                title = L["Others' Setting"],
                type = "dropDown",
                tooltipText = L["Select the timer setting you want to apply to others' timers."],
                func = function()
                    local setting = "otherSetting";
                    local info;
                    for name, settings in AsheylaLib:Alphabetize(TimerLib:Get("timerSettings")) do
                        info = UIDropDownMenu_CreateInfo();
                        info.text = name;
                        info.checked = name == DoTimer:Get(setting);
                        info.func = function() 
                            DoTimer:Set(setting, name);
                            CloseDropDownMenus(); 
                        end
                        UIDropDownMenu_AddButton(info);
                    end
                    
                    info = UIDropDownMenu_CreateInfo();
                    info.text = L["None"];
                    info.tooltipTitle = L["Description"];
                    info.tooltipText = L["If you select 'None', the default for the anchor will be used instead."];
                    info.checked = DoTimer:Get(setting) == nil;
                    info.func = function() 
                        DoTimer:Set(setting, nil);
                        CloseDropDownMenus(); 
                    end
                    UIDropDownMenu_AddButton(info);
                end,
            },
            {
                title = L["Other Timers"],
                type = "editBoxDropDown",
                tooltipText = L["Add here the names of timers other people made that you want to see.  The timer name much match exactly (case insensitive) to be shown."],
                setting = "otherTimers",
            },
        },
        { -- column 3
            {
                title = L["Max Buff Duration"],
                type = "slider",
                tooltipText = L["Sets the maximum duration, in minutes, that a buff can have for DoTimer to track it.  Zero means no restriction."],
                minValue = 0, 
                maxValue = 30,
                valueStep = 2,
                setting = "maxBuffDuration",
                simple = true,
            },
            {
                title = L["Mouseover Fade Time"],
                type = "slider",
                tooltipText = L["Sets the amount of time, in seconds, it takes for mouseover timers to disappear after the mouse is no longer over the unit."],
                minValue = 0, 
                maxValue = 3,
                valueStep = .25,
                setting = "mouseoverFadeTime",
            },
            {
                title = L["Standard Announce"],
                type = "editBoxString",
                tooltipText = L["Sets the message that will be sent when you announce a timer.  You can use the following replacements:\n\n    %s: Name of the timer\n    %d: Time remaining\n    %t: Target name\n    %l: Target level\n    %r: Target raid icon"],
                setting = "standardAnnounce",
                simple = true,
            },
            {
                title = L["No Target Announce"],
                type = "editBoxString",
                tooltipText = L["Sets the message that will be send when you announce a timer with no target.  You can use the following replacements:\n\n    %s: Name of the timer\n    %d: Time remaining"],
                setting = "noTargetAnnounce",
                simple = true,
            },
            {
                title = L["Standard Name"],
                type = "editBoxString",
                tooltipText = L["Sets the text to be displayed as the group name of individual timers moved to another anchor, if the anchor is not set to preserve target data."],
                setting = "ntName",
            },
            {
                title = L["No Target Name"],
                type = "editBoxString",
                tooltipText = L["Sets the text to be displayed as the name of the No Target group.  If you set this to a value another group is also using (in the same anchor), the two groups will merge into one."],
                setting = "ntName",
            },
            {
                title = L["Party Buffs Name"],
                type = "editBoxString",
                tooltipText = L["Sets the text to be displayed as the name of the Party Buffs group.  If you set this to a value another group is also using (in the same anchor), the two groups will merge into one."],
                setting = "pbName",
            },
            {
                title = L["Party Buffs"],
                type = "editBoxDropDown",
                tooltipText = L["This is the list of Party Buffs filters.  Any timer names that match this filter will consolidate into one Party Buff timer.  Prefix with a '^' for it to work as an anti-filter; i.e. if the timer name matches it then it won't be made into a party buff timer."],
                setting = "partyBuffs",
                simple = true,
            },
            {
                title = L["Blocked Timers"],
                type = "editBoxDropDown",
                tooltipText = L["Add here the names of timers you do not wish to see onscreen.  The timer name much match exactly (case insensitive) to be blocked."],
                setting = "blocked",
                simple = true,
            },
        },
    },
    { -- section 2
        { -- column 1
            { -- row 1
                {
                    type = "text",
                    text = L["Select Anchor to Customize: "],
                },
                {
                    title = L["(Select from DropDown Menu)"],
                    type = "dropDown",
                    tooltipText = L["Select the anchor you want to customize."],
                    func = function(self)
                        local info;
                        for name, settings in AsheylaLib:Alphabetize(TimerLib:Get("anchorSettings")) do
                            if name ~= "Default Anchor" and name ~= "DoTimer Mouseover" and name ~= "Notifications Anchor" then
                                info = UIDropDownMenu_CreateInfo();
                                info.text = name;
                                info.checked = name == CURRENT_ANCHOR;
                                info.func = function() 
                                    CURRENT_ANCHOR = name;
                                    getglobal(self:GetParent():GetName() .. "Text"):SetText(name);
                                    for frame in pairs(ANCHOR_FRAMES) do
                                        frame:Update();
                                    end
                                    CloseDropDownMenus(); 
                                end
                                UIDropDownMenu_AddButton(info);
                            end
                        end
                    end,
                    scripts = {
                        OnShow = function(self)
                            for name, settings in pairs(DoTimer:Get("userAnchors")) do
                                if settings.default then
                                    CURRENT_ANCHOR = name;
                                    getglobal(self:GetName() .. "Text"):SetText(name);
                                    for frame in pairs(ANCHOR_FRAMES) do
                                        frame:Update();
                                    end
                                end
                            end
                        end,
                    },
                },
            },
        },
    },
    { -- section 3
        { -- column 1
                {
                    title = L["Default anchor"],
                    type = "checkButton",
                    tooltipText = L["If checked, standard DoTimer targets will be moved to this anchor."],
                    scripts = {
                        OnShow = function(self)
                            if not self.loaded then
                                self.loaded = true;
                                self.Update = function(self)
                                    self:SetChecked(DoTimer:Get("userAnchors", CURRENT_ANCHOR, "default"));
                            end
                            ANCHOR_FRAMES[self] = true;
                        end
                            self:Update();
                        end,
                        OnClick = function(self)
                            if self:GetChecked() then
                                for name, settings in pairs(DoTimer:Get("userAnchors")) do
                                    if name ~= CURRENT_ANCHOR then settings.default = nil; end
                                end
                                DoTimer:Set("userAnchors", CURRENT_ANCHOR, "default", 1);
                            else
                                self:SetChecked(true);
                                AsheylaLib:AlertUser("You cannot uncheck this setting.  You must check it in another anchor to change it.");
                        end
                    end,
                },
            },
            {
                title = "Move PB Here",
                type = "checkButton",
                tooltipText = "If checked, the 'Party Buffs' group will be moved to this anchor.",
                scripts = {
                    OnShow = function(self)
                        if not self.loaded then
                            self.loaded = true;
                            self.Update = function(self)
                                self:SetChecked(DoTimer:Get("userAnchors", CURRENT_ANCHOR, "pbLoc"));
                            end
                            ANCHOR_FRAMES[self] = true;
                        end
                        self:Update();
                    end,
                    OnClick = function(self)
                        if self:GetChecked() then
                            for name, settings in pairs(DoTimer:Get("userAnchors")) do
                                if name ~= CURRENT_ANCHOR then settings.pbLoc = nil; end
                            end
                            DoTimer:Set("userAnchors", CURRENT_ANCHOR, "pbLoc", 1);
                        else
                            DoTimer:Set("userAnchors", CURRENT_ANCHOR, "pbLoc", nil);
                        end
                    end,
                },
            },
        },
        { -- column 2
                {
                    title = L["Move Harmful Here"],
                    type = "checkButton",
                    tooltipText = L["If checked, harmful timers (like DoTs and No Target) will be moved to this anchor."],
                    scripts = {
                        OnShow = function(self)
                            if not self.loaded then
                                self.loaded = true;
                                self.Update = function(self)
                                    self:SetChecked(DoTimer:Get("userAnchors", CURRENT_ANCHOR, "dotLoc"));
                            end
                            ANCHOR_FRAMES[self] = true;
                        end
                            self:Update();
                        end,
                        OnClick = function(self)
                            if self:GetChecked() then
                                for name, settings in pairs(DoTimer:Get("userAnchors")) do
                                    if name ~= CURRENT_ANCHOR then settings.dotLoc = nil; end
                            end
                            DoTimer:Set("userAnchors", CURRENT_ANCHOR, "dotLoc", 1);
                        else
                            DoTimer:Set("userAnchors", CURRENT_ANCHOR, "dotLoc", nil);
                        end
                    end,
                },
            },
            {
                title = "Move NT Here",
                type = "checkButton",
                tooltipText = "If checked, the 'No Target' group will be moved to this anchor.",
                scripts = {
                    OnShow = function(self)
                        if not self.loaded then
                            self.loaded = true;
                            self.Update = function(self)
                                self:SetChecked(DoTimer:Get("userAnchors", CURRENT_ANCHOR, "ntLoc"));
                            end
                            ANCHOR_FRAMES[self] = true;
                        end
                        self:Update();
                    end,
                    OnClick = function(self)
                        if self:GetChecked() then
                            for name, settings in pairs(DoTimer:Get("userAnchors")) do
                                if name ~= CURRENT_ANCHOR then settings.ntLoc = nil; end
                            end
                            DoTimer:Set("userAnchors", CURRENT_ANCHOR, "ntLoc", 1);
                        else
                            DoTimer:Set("userAnchors", CURRENT_ANCHOR, "ntLoc", nil);
                        end
                    end,
                },
            },
        },
        { -- column 3
                {
                    title = L["Move Helpful Here"],
                    type = "checkButton",
                    tooltipText = L["If checked, helpful timers (like HoTs and Party Buffs) will be moved to this anchor."],
                    scripts = {
                        OnShow = function(self)
                            if not self.loaded then
                                self.loaded = true;
                                self.Update = function(self)
                                    self:SetChecked(DoTimer:Get("userAnchors", CURRENT_ANCHOR, "hotLoc"));
                            end
                            ANCHOR_FRAMES[self] = true;
                        end
                            self:Update();
                        end,
                        OnClick = function(self)
                            if self:GetChecked() then
                                for name, settings in pairs(DoTimer:Get("userAnchors")) do
                                    if name ~= CURRENT_ANCHOR then settings.hotLoc = nil; end
                            end
                            DoTimer:Set("userAnchors", CURRENT_ANCHOR, "hotLoc", 1);
                        else
                            DoTimer:Set("userAnchors", CURRENT_ANCHOR, "hotLoc", nil);
                        end
                    end,
                },
            },
            {
                title = "Move Others' Here",
                type = "checkButton",
                tooltipText = "If checked, timers created from the 'Other Timers' setting will be moved to this anchor.  These timers will be moved along with their target data.",
                scripts = {
                    OnShow = function(self)
                        if not self.loaded then
                            self.loaded = true;
                            self.Update = function(self)
                                self:SetChecked(DoTimer:Get("userAnchors", CURRENT_ANCHOR, "otherLoc"));
                            end
                            ANCHOR_FRAMES[self] = true;
                        end
                        self:Update();
                    end,
                    OnClick = function(self)
                        if self:GetChecked() then
                            for name, settings in pairs(DoTimer:Get("userAnchors")) do
                                if name ~= CURRENT_ANCHOR then settings.otherLoc = nil; end
                            end
                            DoTimer:Set("userAnchors", CURRENT_ANCHOR, "otherLoc", 1);
                        else
                            DoTimer:Set("userAnchors", CURRENT_ANCHOR, "otherLoc", nil);
                        end
                    end,
                },
            },
        },
    },
    {
        {
            { -- row
                {
                    type = "text",
                    small = true,
                    text = L["Move these targets here:"],
                },
                {
                    title = L["<Target Name>"],
                    type = "editBoxDropDown",
                    tooltipText = L["Type in here the names of targets whose timers you want moved to this anchor.  The target must match exactly what you type (case insensitive) in order to move.  You can type '*target*' or '*focus*' (no quotes) for your current target/focus."],
                    scripts = {
                		OnEnterPressed = function(self) 
                			local text = self:GetText();
                			DoTimer:Set("userAnchors", CURRENT_ANCHOR, "targets", string.lower(text), 1);
                            self:ClearFocus();
                		end,
                    },
                    func = function()
                        local targets = DoTimer:Get("userAnchors", CURRENT_ANCHOR, "targets");
                        if targets then
                            local info;
                            for name in pairs(targets) do
                                info = UIDropDownMenu_CreateInfo();
                                info.text = name;
                                info.notCheckable = 1;
                                info.func = function() 
                                    DoTimer:Set("userAnchors", CURRENT_ANCHOR, "targets", name, nil);
                                    CloseDropDownMenus(); 
                                end
                                UIDropDownMenu_AddButton(info);
                            end
                        end
                    end,
                },
                {
                    title = L["For Below Timers"],
                    type = "checkButton",
                    tooltipText = L["If checked, only the timers added to the editbox below will be moved to this anchor for the targets you specify."],
                    scripts = {
                        OnShow = function(self)
                            if not self.loaded then
                                self.loaded = true;
                                self.Update = function(self)
                                    self:SetChecked(DoTimer:Get("userAnchors", CURRENT_ANCHOR, "specificTimers"));
                                end
                                ANCHOR_FRAMES[self] = true;
                            end
                            self:Update();
                        end,
                        OnClick = function(self)
                            if self:GetChecked() then
                                DoTimer:Set("userAnchors", CURRENT_ANCHOR, "specificTimers", 1);
                            else
                                DoTimer:Set("userAnchors", CURRENT_ANCHOR, "specificTimers", nil);
                            end
                        end,
                    },
                },
            },
            { -- row
                {
                    type = "text",
                    small = true,
                    text = L["Move these timers here:"],
                },
                {
                    title = L["<Timer Name>"],
                    type = "editBoxDropDown",
                    tooltipText = L["Type in here the names of individual timers you want moved to this anchor.  The timer name must match only a fragment (case insensitive) in order to move."],
                    scripts = {
                		OnEnterPressed = function(self) 
                			local text = self:GetText();
                			DoTimer:Set("userAnchors", CURRENT_ANCHOR, "timers", string.lower(text), 1);
                            self:ClearFocus();
                		end,
                    },
                    func = function()
                        local timers = DoTimer:Get("userAnchors", CURRENT_ANCHOR, "timers");
                        if timers then
                            local info;
                            for name in pairs(timers) do
                                info = UIDropDownMenu_CreateInfo();
                                info.text = name;
                                info.notCheckable = 1;
                                info.func = function() 
                                    DoTimer:Set("userAnchors", CURRENT_ANCHOR, "timers", name, nil);
                                    CloseDropDownMenus(); 
                                end
                                UIDropDownMenu_AddButton(info);
                            end
                        end
                    end,
                },
                {
                    title = L["Preserve Tar. Data"],
                    type = "checkButton",
                    tooltipText = L["If checked, the timers moving into this anchor will preserve their target information.  If unchecked, the timers will use the 'Standard Name' setting to determine their group."],
                    scripts = {
                        OnShow = function(self)
                            if not self.loaded then
                                self.loaded = true;
                                self.Update = function(self)
                                    self:SetChecked(DoTimer:Get("userAnchors", CURRENT_ANCHOR, "preserveTarget"));
                                end
                                ANCHOR_FRAMES[self] = true;
                            end
                            self:Update();
                        end,
                        OnClick = function(self)
                            if self:GetChecked() then
                                DoTimer:Set("userAnchors", CURRENT_ANCHOR, "preserveTarget", 1);
                            else
                                DoTimer:Set("userAnchors", CURRENT_ANCHOR, "preserveTarget", nil);
                            end
                        end,
                    },
                },
            },
            { -- row
                {
                    type = "text",
                    small = true,
                    text = L["Apply this timer setting:"],
                },
                {
                    title = L[""],
                    type = "dropDown",
                    tooltipText = L["Select the timer setting you want to apply to specific timers."],
                    func = function()
                        local info;
                        for name, settings in AsheylaLib:Alphabetize(TimerLib:Get("timerSettings")) do
                            info = UIDropDownMenu_CreateInfo();
                            info.text = name;
                            info.checked = name == CURRENT_TIMER;
                            info.func = function() 
                                CURRENT_TIMER = name;
                                CloseDropDownMenus(); 
                            end
                            UIDropDownMenu_AddButton(info);
                        end
                    end,
                    scripts = {
                        OnShow = function(self)
                            CURRENT_TIMER = "Default Timer";
                        end,
                    },
                },
                {
                    type = "text",
                    small = true,
                    text = L["to these timers:"],
                },
                {
                    title = L["<Timer Name>"],
                    type = "editBoxDropDown",
                    tooltipText = L["Type in here the names of timers you want to apply to the timer setting.  The timer name must match only a fragment (case insensitive) to apply."],
                    scripts = {
                		OnEnterPressed = function(self) 
                			local text = self:GetText();
                			DoTimer:Set("userAnchors", CURRENT_ANCHOR, "timerSettings", CURRENT_TIMER, string.lower(text), 1);
                            self:ClearFocus();
                		end,
                    },
                    func = function()
                        local timers = DoTimer:Get("userAnchors", CURRENT_ANCHOR, "timerSettings", CURRENT_TIMER);
                        if timers then
                            local info;
                            for name in pairs(timers) do
                                info = UIDropDownMenu_CreateInfo();
                                info.text = name;
                                info.notCheckable = 1;
                                info.func = function() 
                                    DoTimer:Set("userAnchors", CURRENT_ANCHOR, "timerSettings", CURRENT_TIMER, name, nil);
                                    CloseDropDownMenus(); 
                                end
                                UIDropDownMenu_AddButton(info);
                            end
                        end
                    end,
                },
            },
        },
    },
};

local optionsTable2 = {
    { -- section 1
        { -- column 1
            {
                title = L["Simple Mode"],
                type = "checkButton",
                tooltipText = L["Uncheck to access the more complex features of DoTimer."],
                scripts = {
                    OnShow = function(self) 
                        local setting = AsheylaLib:InSimpleMode();
                        self:SetChecked(setting and true or false); 
                    end,
                    OnClick = function(self) 
                        AsheylaLib:SetSimpleMode(self:GetChecked() and true or false);
                        GUILib:ReloadGUI();
                    end,
                },
            },
            {
                type = "text",
                text = L["Version Info:"],
            },
            {
                type = "text",
                small = true,
                text = L["   |cffffffffNumber|r: |cff00ff00"] .. AsheylaLib:ReturnVersion(),
            },
            {
                type = "text",
                small = true,
                text = L["   |cffffffffReleased|r: |cff00ff00"] .. AsheylaLib:ReturnDateUploaded(),
            },
        },
    },
    { -- section 2
        { -- column 1
            {
                type = "text",
                text = L["Author Info:"],
            },
            {
                type = "text",
                small = true,
                text = L["   |cffffffffName|r: |cff00ff00Ross Nichols"],
            },
            {
                type = "text",
                small = true,
                text = L["   |cffffffffE-Mail|r: |cff00ff00ross456@gmail.com"],
            },
            {
                type = "text",
                small = true,
                text = L["   |cffffffffSchool|r: |cff00ff00University of Florida"],
            },
            {
                type = "text",
                small = true,
                text = L["   |cffffffffCharacters|r: |cff00ff00Asheyla (Shattered Hand Horde), Xanido (Anetheron Alliance)"],
            },
        },
    },
    { -- section 3
        { -- column 1
            {
                type = "text",
                text = L["AddOn Info:"],
            },
            {
                type = "text",
                small = true,
                text = L["   |cffffffffDoTimer|r: |cff00ff00/dotimer|r or |cff00ff00/dot"],
            },
            {
                type = "text",
                small = true,
                text = L["   |cffffffffCooldowns|r: |cff00ff00/cooldowns|r or |cff00ff00/cd"],
            },
            {
                type = "text",
                small = true,
                text = L["   |cffffffffNotifications|r: |cff00ff00/notifications|r or |cff00ff00/not"],
                notSimple = true,
            },
            {
                type = "text",
                small = true,
                text = L["   |cffffffffPlayerAuras|r: |cff00ff00/playerauras|r or |cff00ff00/pa"],
                notSimple = true,
            },
            {
                type = "text",
                small = true,
                text = L["   |cffffffffTimerLib|r: |cff00ff00/timerlib|r or |cff00ff00/tl"],
                notSimple = true,
            },
            {
                type = "text",
                small = true,
                text = L["      Type |cff00ff00/timerlib anchor|r or |cff00ff00/timerlib a|r to open\n      to Anchors.  Else, it will open to Timers."],
                notSimple = true,
            },
        },
    },
    { -- section 4
        { -- column 1
            {
                type = "text",
                text = L["Profiles"],
            },
            {
                title = L["Create / Delete"],
                type = "editBoxString",
                tooltipText = L["Type in here the name of a profile to create or delete.  If a profile by the name already exists, it will be deleted.  Else, a new one with that name will be made."],
                scripts = {
                    OnEditFocusGained = function(self) 
                        self:SetText(""); 
                        self:HighlightText(); 
                    end,
            		OnEditFocusLost = function(self) self:SetText(self.title or ""); self:SetCursorPosition(0); end,
            		OnShow = function(self) self:SetText(self.title or ""); self:SetCursorPosition(0); end,
            		OnEscapePressed = function(self)
                        self:SetText(self.title or ""); self:SetCursorPosition(0);
            			self:ClearFocus();
            		end,
            		OnEnterPressed = function(self) 
                        local name = self:GetText();
            			if AsheylaLib_Settings[name] then
                            if name == ASHEYLALIB_ACTIVE_PROFILE then
                                AsheylaLib:AlertUser(L["You cannot delete the active profile."]);
                            elseif name == "Default" then
                                AsheylaLib:AlertUser(L["You cannot delete the default profile."]);
                            elseif name == "simpleMode" then
                                AsheylaLib:AlertUser(L["That's an invalid name.  Try a different one."]);
                            else
                                AsheylaLib_Settings[name] = nil;
                            end
                        elseif name ~= "" then
                            AsheylaLib:SetActiveProfile(name);
                            for frame in pairs(PROFILE_FRAMES) do
                                frame:Update();
                            end
                        end
                        self:ClearFocus();
            		end,
                },
            },
            { -- row
                {
                    type = "text",
                    small = true,
                    text = L["Set active profile:"],
                },
                {
                    title = L["(Select from DropDown Menu)"],
                    type = "dropDown",
                    tooltipText = L["Select the profile you want to be active."],
                    func = function(self)
                        local info;
                        for name, vals in AsheylaLib:Alphabetize(AsheylaLib_Settings) do
                            if type(vals) == "table" then
                                info = UIDropDownMenu_CreateInfo();
                                info.text = name;
                                info.checked = name == ASHEYLALIB_ACTIVE_PROFILE;
                                info.func = function() 
                                    AsheylaLib:SetActiveProfile(name);
                                    for frame in pairs(PROFILE_FRAMES) do
                                        frame:Update();
                                    end
                                    CloseDropDownMenus(); 
                                end
                                UIDropDownMenu_AddButton(info);
                            end
                        end
                    end,
                    scripts = {
                        OnShow = function(self)
                            if not self.loaded then
                                self.loaded = true;
                                PROFILE_FRAMES[self] = 1;
                                self.Update = function(self)
                                    getglobal(self:GetName() .. "Text"):SetText(ASHEYLALIB_ACTIVE_PROFILE);
                                end
                            end
                            self:Update();
                        end,
                    },
                },
            },
            {
                title = L["Make this the default profile for this character."],
                type = "checkButton",
                tooltipText = L["If checked, this profile will be set to active when you log in on this character.  If none are checked, 'Default' will be loaded."],
                scripts = {
                    OnShow = function(self) 
                        if not self.loaded then
                            self.loaded = true;
                            PROFILE_FRAMES[self] = 1;
                            self.Update = function(self)
                                local id = UnitName("player") .. "-" .. GetRealmName();
                                self:SetChecked(AsheylaLib_Settings[ASHEYLALIB_ACTIVE_PROFILE][id] and true or false);
                            end
                        end
                        self:Update();
                    end,
                    OnClick = function(self) 
                        local val = self:GetChecked() and true or nil;
                        local id = UnitName("player") .. "-" .. GetRealmName();
                        if val then
                            for name, settings in pairs(AsheylaLib_Settings) do
                                if type(settings) == "table" then settings[id] = nil; end
                            end
                        end
                        AsheylaLib_Settings[ASHEYLALIB_ACTIVE_PROFILE][id] = val;
                    end,
                },
            },
            {
                title = L["Copy a profile into this one."],
                type = "dropDown",
                tooltipText = L["Selecting a profile from this dropdown will make your active profile be a clone of the selected one."],
                func = function()
                    local info;
                    if UIDROPDOWNMENU_MENU_LEVEL == 1 then
                        for name, vals in AsheylaLib:Alphabetize(AsheylaLib_Settings) do
                            if type(vals) == "table" and name ~= ASHEYLALIB_ACTIVE_PROFILE then
                                info = UIDropDownMenu_CreateInfo();
                                info.text = name;
                                info.notCheckable = true;
                                info.func = function()
                                    AsheylaLib:CopyFromProfile(name);
                                end
                                UIDropDownMenu_AddButton(info);
                            end
                        end
                    elseif UIDROPDOWNMENU_MENU_LEVEL == 2 then -- shouldn't execute anymore
                        for _, module in ipairs({"All Modules", "DoTimer", "Cooldowns", "Notifications", "PlayerAuras", "TimerLib"}) do
                            info = UIDropDownMenu_CreateInfo();
                            info.text = module;
                            info.notCheckable = true;
                            info.func = function()
                                AsheylaLib:CopyFromProfile(UIDROPDOWNMENU_MENU_VALUE, module ~= "All Modules" and module or nil);
                            end
                            UIDropDownMenu_AddButton(info, UIDROPDOWNMENU_MENU_LEVEL);
                        end
                    end
                end,
            },
        }
    },
};

local function defaultFunc()
    AsheylaLib:ClearAllSettings();
end

local function createDGUI()
    GUILib:SetGUIPanel("DoTimer", "main", DoTimer, optionsTable2, {allSimple = true, default = defaultFunc});
    GUILib:SetGUIPanel("DoTimer", "DoTimer", DoTimer, optionsTable);
end
createDGUI();
GUILib:AddGUICreationScript(createDGUI);
